home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / mike40c.arc / BRK.ASM < prev    next >
Assembly Source File  |  1986-10-23  |  5KB  |  164 lines

  1. page,132
  2. title BRK.ASM - BREAK PROCEDURES for MICROSOFT 'C' (4.0)
  3. ;
  4. ;  This program will take control of the keyboard interupt vector
  5. ;  and disable the CTRL key, eliminating the CTRL-C or CTRL-BREAK
  6. ;  during program execution.  Because this handler does not stay
  7. ;  resident it must be reset prior to exiting the program. I used
  8. ;  some unusual techniques in this code just for fun.
  9. ;
  10. ;      brk_off();    Turn off CTRL key.
  11. ;      brk_on();     Turn CTRL on and reset vector.
  12. ;
  13. ;                               by Mike Elkins   10-10-86
  14. ;
  15. ;
  16.  
  17. _romdata    segment at 0h
  18.     org  417h                           ;Ctrl shift flag offset
  19. _keyflag  label byte                    ;here's where we'll access it
  20. _romdata  ends
  21.  
  22. _text       segment byte public 'code'
  23.             assume  cs:_text
  24.  
  25.  
  26. ;-----establish interrupt vector
  27.  
  28.         public  _brk_off
  29. _brk_off    proc    near
  30.  
  31. ;    first check to see if brk_int is already loaded
  32.         pushf                        ;save calling int status
  33.         cli
  34.         mov    ah,35h                ;get vector
  35.         mov    al,09h                ;keyboard vector #
  36.         int    21h
  37.  
  38. ;    check the keyboard interrupt vector (in es:bx)
  39.         cmp    bx,offset brk_int     ;check offset portion
  40.         jne    on001                 ;not same
  41.         mov    ax,es
  42.         cmp    ax,seg brk_int        ;check segment portion
  43.         je     on002                 ;same
  44.  
  45. ;    save away origional vector
  46. on001:  mov    cs:rom_key_int,bx     ;offset to storage
  47.         mov    ax,es
  48.         mov    cs:rom_key_int[2],ax  ;segment to storage
  49.  
  50. ;    load our vector
  51.         push    ds                   ;temp save
  52.         mov     ax,seg brk_int
  53.         mov     ds,ax
  54.         mov     dx,offset brk_int    ;replace with our interrupt
  55.         mov     ah,25h               ;set vector
  56.         mov     al,09h               ;vector number
  57.         int     21h
  58.         pop     ds                   ;recover
  59.         popf                         ;recover int status
  60.         ret
  61.  
  62. ;    already loaded - exit with error flag
  63. on002:        popf
  64.         mov     ax,-1                 ;set error
  65.         ret
  66.  
  67. _brk_off    endp
  68.  
  69. page +
  70. ;----- terminates interrupt vector
  71.  
  72.         public    _brk_on
  73. _brk_on    proc    near
  74.  
  75. ;    test for vector in storage
  76.         cmp     cs:rom_key_int[2],0
  77.         je      of001            ;no - exit
  78.  
  79. ;    restore old vector
  80.         pushf
  81.         cli
  82.         push    ds                     ;temp save
  83.         mov     dx,cs:rom_key_int      ;offset portion
  84.         mov     ax,cs:rom_key_int[2]   ;segment portion
  85.         mov     ds,ax
  86.         mov     ah,25h                 ;set vector
  87.         mov     al,09h                 ;keyboard vector #
  88.         int     21h
  89.         pop     ds                     ;restore
  90.         popf
  91.  
  92. of001:
  93.         ret
  94.  
  95. _brk_on    endp
  96.  
  97. page +
  98. ;------ This procedure responds to keyboard interrupt (09h)
  99. ;
  100. brk_int:
  101.         sti
  102.     push    ax
  103.     push    bx
  104.     push    dx
  105.     push    ds
  106.     push    es
  107.     push    si
  108.     push    di
  109.     push    bp
  110.  
  111.         assume  ds:_romdata     
  112.         mov     ax, _romdata
  113.         mov     ds,ax
  114.         test    byte ptr _keyflag, 04h  ;Check for Ctrl shift state
  115.         jz      key_released
  116.         in      al,060h                 ;read keyboard
  117.         test    al,080h                 ;see if key release
  118.         jnz     key_released            ;ignore if released
  119.         cmp     al,02eh                 ;scan for C key
  120.         jz      brk_hit                 ;no, handle normally
  121.         cmp     al,046h                 ;scan for scroll lock key
  122.         jz      brk_hit                 ;no, handle normally
  123.         jmp     brk_exit
  124. ;
  125. ; Get rid of CTRL key
  126. ;
  127. brk_hit:
  128.         in      al,061h                 ;read 8255 port
  129.         or      al,080h                 ;set ack signal bit
  130.         out     061h,al                 ;send ack to port
  131.         and     al,07fh                 ;reset ack bit
  132.         out     061h,al                 ;restor port status
  133. ;
  134.         mov     al,020h                 ;send EOI to 8259
  135.         out     020h,al
  136. ;        
  137.         pop     bp
  138.         pop     di
  139.         pop     si
  140.         pop     es
  141.         pop     ds
  142.         pop     dx
  143.         pop     bx
  144.         pop     ax
  145.         iret
  146. ;
  147. key_released:
  148. brk_exit:
  149.            pop    bp
  150.            pop    di
  151.            pop    si
  152.            pop    es
  153.            pop    ds
  154.            pop    dx
  155.            pop    bx
  156.            pop    ax
  157.             db    0eah              ; long-jump to old vector
  158. ;
  159. rom_key_int    dw      2 dup (?)    ;contains the ROM jump-to-address
  160.  
  161. _text        ends
  162.  
  163.         end
  164.